home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-13 | 6.4 KB | 220 lines | [TEXT/YERK] |
- \ Construct table of names & traps for toolbox calls
- \ Modification History
- \ 4/23/84 CBD Version 1.0
- \ 12/29/85 cdn Improved asmCall to accept upper/lower case
- \ 6/11/86 cdn Added Mac Plus toolbox calls; generally improved code
- \ 6/28/86 cdn Added call Pack routines by name
- \ 7/01/86 ndc Added hash collision resolution
- \ 8/28/86 cdn Added fcall
- \ 9/03/86 rfd Modified Tools" for HFS compatability (no reopen)
- \ 6/16/87 rfl Added calls for MacII
- \ 8/28/88 rfl increased collision table to 10 bytes because of
- \ confusion with dispospixmap and dispospixpat ETC.
- \ Make sure to vary name,trap,parm,pibx, and ctable sizes
- \ Also, all traps must be in one text file to be read in
- \ 8/31/88 rfl changed allot to reserve to fix error in modulation
- \ the second pass must equal the first pass in data errors
- \ or else the module code will figure the difference is an addr
- \ which must be relocated
- \ 9/19/88 rfl added popupmenu traps
- \ 10/07/89 rfl increase to 1000 and 120
- \ 8/13/90 rfl modify sizes
- \ 12/15/90 rfl moved gtool here
- \ 2/07/91 rfl increased globals
- \ 2/17/91 rfl modified for use with Michael Hore's 32bit hash routine.
- \ collisions are VERY rare.
- \ 7/02/91 rfl allow hex values for parms
- \ 10/25/91 rfl fixed occasional bug in hex value code
- \ 11/9/95 rfl ok, really modified to use data files in the yerk folder that
- \ hold the trap hashes and inline codes, so the module doesn't
- \ exceed the 32k limit.
-
- Decimal
-
- :Module Tool1
-
- 0 value names
- sarray inLines
-
- hex
- \ ( str255addr -- hashVal ) hash a name into a 32-bit word
- create HashName
- 2057 w, \ move.l (sp),a0
- d1cb w, \ adda.l a3,a0
- 7000 w, \ moveq #0,d0 \ Result will go to D0
- 7400 w, \ moveq #0,d2
- 1418 w, \ move.b (a0)+,d2 \ Count
- c43c007f , \ and.b #127,d2 \ Clear top bit in case it's a name field
- 60000008 , \ bra lptest
- ef98 w, \ loop rol.l #7,d0
- 1218 w, \ move.b (a0)+,d1
- b300 w, \ eor.b d1,d0 \ b300
- 51cafff8 , \ lptest dbra d2,loop
- 08c0001f , \ bset #31,d0
- 2e80 w, \ move.l d0,(sp)
- next,
- decimal
-
- ( str255 chr -- offs t OR f )
- : charOf { addr chr \ flag -- } false -> flag
- addr c@ 0 1 ++> addr
- DO
- addr i+ c@ chr = IF i true -> flag leave THEN
- LOOP flag
- ;
-
-
- : load new: inLines
- new: loadfile " trapHash" name: topfile
- openReadOnly: topfile abort" open Error"
- 0 sp@ 4 read: topfile drop heap> ordered-col -> names
- names length: names read: topfile drop
- close: topfile drop
- " InLines" name: topfile
- openReadOnly: topfile abort" open error"
- 0 sp@ 4 read: topfile drop putLimit: inLines
- topfile size: topfile 4 - read: inlines drop
- remove: loadfile
- \ lock: inlines get: inlines scount putLimit: inlines
- size: names limit: inlines <> abort" sizes don't match" ;
-
- true value notLoaded?
-
- : endTool dispose> names release: inlines true -> notLoaded? ;
-
- : findTrap { addr len \ flag -- addr' } false -> flag
- addr addr len + 2-
- DO ic@ $ F0 and $ A0 = IF i true -> flag LEAVE THEN -2 +LOOP
- flag ;
-
- \ ( str255 -- addr len ) Get Trap word for a call index
- : @Trap { tStr \ mStr addr len idx amod -- } 0 -> mStr 0 -> amod
- tStr ascii , charOf \ stop short of comma if any
- IF dup tStr c! tStr + 2+ -> mStr THEN
- tStr HashName indexOf: names 0= ?error 150
- -> idx idx at: inLines -> len -> addr
- mStr \ modifier bits if any
- IF " REGS" mstr over s= IF $ 01 -> amod THEN \ GetTrapAddr
- " ASYNC" mstr over s= IF $ 04 -> amod THEN \ device drivers
- " IMMED mstr over s= IF $ 02 -> amod THEN \ control calls
- " SYS" mstr over s= IF $ 04 -> amod THEN \ Memory Manager
- " CLEAR" mstr over s= IF $ 02 -> amod THEN
- " MARKS" mstr over s= IF $ 04 -> amod THEN \ String Compares
- " CASE" mstr over s= IF $ 02 -> amod THEN
- amod 0= ?error 193
- addr len findTrap not ?error 193 \ modifiers will now work with this type
- addr - pad + -> idx
- addr pad len cmove
- amod idx c@ or idx c!
- pad -> addr
- THEN
- addr len ;
-
- hex
- create trapJmp
- 205f w, \ move.l (sp)+,a0
- d1cb w, \ adda.l a3,a0
- 4ed0 w, \ jmp (a0)
- next,
- decimal
- \ used for traps from interpreter
- : ttrapw <builds 40 reserve does> cflush trapJmp ;
- ttrapw trapper
-
- 'c trapper 8+ value ^trapper
- \
- : tw, ( addr n -- addr') swap >r r w! r> 2+ ;
-
- : call1 notLoaded? IF load false -> notLoaded? THEN
- @word @trap \ get addr len of trap inline
- state \ is it compile state?
- IF compile inLine \ yes, so compile 'inLine' to start a code word
- here over allot swap cmove \ compile inline code at here
- $ 49fA0006 , \ lea *+8,a4 to reset IP to follow the code
- compile next, \ next, to end the code word
- ELSE ^trapper swap >r r cmove \ fill interp trap field with inline and save len
- ^trapper r> + $ 4eeb tw, next tw, \ add next,
- drop trapper \ drop addr from tw, and execute
- THEN ; immediate \ interp resumes here
-
- : asmcall1 notLoaded? IF load false -> notLoaded? THEN
- str255 1+ buf255 c@ >uc
- buf255 @Trap
- here over allot swap cmove ;
-
- : fcall1 ( fcb --) state
- IF compile >r compile word0 compile r> compile +base ELSE >r word0 r> +base THEN
- [compile] call1 state IF compile i->l ELSE i->l THEN ; immediate
-
- \
- \ \ Trap dispatcher for low-level File Manager
- \ : fCall
- \ @word @Trap
- \ State
- \ IF Compile Lit
- \ IF ELSE 0 THEN
- \ w, w, Compile (fdos)
- \ ELSE IF makeInt THEN
- \ (fdos)
- \ THEN
- \ ; Immediate
- \
- \
- \ ************
-
- 182 ordered-col gNames
- 182 wordCol globals
-
-
- \ ( -- ) Get next word, add if global name
- : globalName
- @word hex number drop ( global addr )
- @word
- HashName dup indexOf: gNames ( trap# hashval [idx] bool )
- IF . abort" collision" \ mark collision item
- ELSE add: gNames add: globals
- THEN ;
-
- \ read toolbox name/trap table and fill arrays
- : Tools" { \ radix cecho -- }
- 1 tface ." Loading globals…" 0 tface
- base -> radix decho -> cecho
- new: loadFile setName: topFile
- openReadOnly: topFile ?error 149
-
- 0 moveTo: topFile drop
- query: topFile drop
- BEGIN \ read until eof
- tib c@ ascii \ <> \ skip comments
- IF globalName THEN
- query: topFile
- UNTIL
- -echo
-
- remove: loadFile
- radix -> base cecho -> decho ;
-
- \ load the calls into the symbol table
- Tools" ::Module source:globals
- forget globalName \ dump table generation code
-
- CR
- size: globals . ." routine gNames stored" CR
-
- \ ( str255 -- global ) Get global word for a global index
- : @global { tStr -- }
- tStr HashName indexOf: gNames 0= ?error 150
- dup ^elem: globals w@ ( idx trap/flag )
- swap drop ;
-
- \ global dispatcher
- : global1
- @word @global
- state
- IF compile lit , 'c -base ,
- ELSE -base
- THEN
- ; Immediate
-
- ;Module
-